﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainProject.Quanlykhachhang
{
    public partial class Suakhachhang : Form
    {
        int khachhang;
        public Suakhachhang()
        {
            InitializeComponent();
            QLXT_DBDataContext qlxt_db = new QLXT_DBDataContext();
        }

        public Suakhachhang(int idkh)
        {
            InitializeComponent();
            khachhang = idkh;
        }

        private void bnt_Sua_Click(object sender, EventArgs e)
        {
            QLXT_DBDataContext qlxt_db = new QLXT_DBDataContext();
            string strTen = txt_Ten.Text;
            string strDiachi = txt_Diachi.Text;
            string strDienthoai = txt_Dienthoai.Text;
            string strEmail = txt_Email.Text;
            string strGhichu = rtxt_Ghichu.Text;

            if (strTen == string.Empty || strDienthoai == string.Empty || strDiachi == string.Empty || strEmail == string.Empty)
            {
                MessageBox.Show(@"Vui long nhap day du Ho&ten, dienthoai, email, dia chi cua khach hang", @"Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            KHACHHANG kh = qlxt_db.KHACHHANGs.Single(p => p.IDKHACHHANG == int.Parse(txt_Maso.Text));
            kh.TENKHACHHANG = strTen;
            kh.DIACHI = strDiachi;
            kh.EMAIL = strEmail;
            kh.PHONE = strDienthoai;
            kh.GHICHU = strGhichu;

            qlxt_db.SubmitChanges();

            this.Close();
        }

        private void Suakhachhang_Load(object sender, EventArgs e)
        {
            QLXT_DBDataContext qlxt_db = new QLXT_DBDataContext();
            KHACHHANG kh = qlxt_db.KHACHHANGs.Single(p => p.IDKHACHHANG == khachhang);
            txt_Ten.Text = kh.TENKHACHHANG;
            txt_Diachi.Text = kh.DIACHI;
            txt_Email.Text = kh.EMAIL;
            txt_Dienthoai.Text = kh.PHONE;
            rtxt_Ghichu.Text = kh.GHICHU;
            txt_Maso.Text = khachhang.ToString();
        }

        private void bnt_Thoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Suakhachhang_FormClosing(object sender, FormClosingEventArgs e)
        {
        }
    }
}
